#include <QFuture>
#include <QList>
#include <cmath>
#include <QDebug>
#include <QtConcurrentMap>
#include <QtCore/QCoreApplication>

struct Interval {

	double left;
	double right;

	Interval() {}
	Interval(double left, double right): left(left), right(right) {}
};

double mapFunction(Interval interval) {
	return  sin((interval.right + interval.left) / 2) * (interval.right - interval.left);
}

void reduceFunction(double& result, double x) {
	result += x;
}

int main(int argc, char *argv[])
{
	QCoreApplication app(argc, argv);

	const double step = 1e-5;
	QList<Interval> intervals;
	for (double i = 0; i < M_PI; i += step) {
		intervals.append(Interval(i, i + step));
	}

	QFuture<double> result = QtConcurrent::mappedReduced(
				intervals.begin(), intervals.end(), mapFunction, reduceFunction);

	result.waitForFinished();
	qDebug() << *result.begin();
}

